#define _CRT_SECURE_NO_WARNINGS 1
#include "Stack.h"

void Stack::Push(int x) {
	if (_top == _capacity) {
		int newCapacity = 2 * _capacity;
		int* tmp = (int*)realloc(_a, sizeof(int) * newCapacity);
		if (tmp == nullptr) {
			perror("realloc failed:");
			exit(1);
		}
		_a = tmp;
		_capacity = newCapacity;
	}
	_a[_top++] = x;
}

void Stack::Init() {
	_a = (int*)malloc(sizeof(int) * 4);
	_capacity = 4;
	_top = 0;
}

void Stack::Pop() {
	assert(_top != 0);
	_top--;
}